All files / src/app/(site)/support/articles/[slug] page.tsx

0% Statements 0/55
100% Branches 0/0
0% Functions 0/1
0% Lines 0/55

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                                               
export const dynamic = "force-dynamic";

import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { prisma } from '@/lib/prisma';
import ArticleView from '@/components/features/support/FAQ/ArticleView';

interface PageProps {
  params: Promise<{ slug: string }>;
}

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
  const { slug } = await params;
  const article = await prisma.supportArticle.findUnique({
    where: { slug },
    select: { title: true, summary: true }});

  if (!article) {
    return { title: 'Article Not Found | Elite Events' };
  }

  return {
    title: `${article.title} | Help Center | Elite Events`,
    description: article.summary};
}

export default async function ArticlePage({ params }: PageProps) {
  const { slug } = await params;

  // Get article and increment view count
  const article = await prisma.supportArticle.update({
    where: { slug, isPublished: true },
    data: { viewCount: { increment: 1 } },
    select: {
      id: true,
      slug: true,
      title: true,
      summary: true,
      content: true,
      category: true,
      keywords: true,
      isPublished: true,
      viewCount: true,
      helpfulCount: true,
      notHelpfulCount: true,
      createdAt: true,
      updatedAt: true,
      publishedAt: true}}).catch(() => null);

  if (!article) {
    notFound();
  }

  return <ArticleView article={article} />;
}